import os
import time

from selenium import webdriver
from selenium.webdriver.common.by import By


class Log_on:

    def __init__(self):
        # 打开浏览器
        self.driver = webdriver.Chrome()
        # 最大化浏览器
        self.driver.maximize_window()
        # 进入QQ邮箱登录网页
        self.driver.get('https://mail.qq.com/')

    def log(self):
        self.driver.switch_to.frame('login_frame')
        # 定位QQ输入框并输入QQ
        time.sleep(2)
        QQ = self.driver.find_element(By.ID, 'u')
        QQ.send_keys('525855722')
        # 定位密码输入框并输入密码
        time.sleep(2)
        password = self.driver.find_element(By.ID, 'p')
        password.send_keys('12345678')
        # 定位登录按钮并点击登录
        time.sleep(2)
        login_button = self.driver.find_element(By.ID, 'login_button')
        login_button.click()

    def quit(self):
        time.sleep(2)
        #关闭浏览器
        self.driver.quit()


if __name__ == '__main__':
    log_on = Log_on()
    log_on.log()
    log_on.quit()